﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SceneMgr : MonoBehaviour
{
    public static SceneMgr Instance;
    private void Awake()
    {
        Screen.sleepTimeout = SleepTimeout.NeverSleep; //并不是百分百有效
        Instance = this;
    }

    private void OnDestroy()
    {
        Instance = null;
    }

    private SceneBase _curScene;
    public void SetCurScene(SceneBase curScene)
    {
        _curScene = curScene;
    }
    public void LoadScene(string sceneName, System.Object data=null)
    {
        _curScene = null;
        UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, UnityEngine.SceneManagement.LoadSceneMode.Single);
        if (data != null)
            StartCoroutine(coWaitSetCurScene(data));
    }

    IEnumerator coWaitSetCurScene(System.Object data)
    {
        yield return new WaitUntil(()=> { return _curScene != null; });
        _curScene.OnHandleData(data);
    }
}

public class SceneName
{
    public const string SceneLogin = "SceneLogin";
    public const string SceneMain = "SceneMain";
    public const string SceneBattle = "SceneBattle";
}